package com.hbean.system.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: 注册自定义拦截器
 * 设置拦截的和不拦截的请求，不拦截静态资源
 * @Project: hbean
 * @Author: hjibo
 * @CreateDate: 2018-10-01 00:36
 * @ModificationHistory:
 */

@Slf4j
@Configuration
@EnableWebMvc
public class RegInterceptor implements WebMvcConfigurer {

    @Autowired
    private SysInterceptor sysInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器，添加拦截路径和排除拦截路径
        log.info("###### 注册拦截器 ######");
        registry.addInterceptor(sysInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","/toLogin","/login/loginIn","/login/loginOff","/static/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
